package com.weipai.springboot.module.service.impl;

import com.weipai.springboot.enums.RetCode;
import com.weipai.springboot.model.api.PageResult;
import com.weipai.springboot.model.api.Response;
import com.weipai.springboot.module.dao.GoodsDao;
import com.weipai.springboot.module.dao.InventoryDao;
import com.weipai.springboot.module.dao.ProductDao;
import com.weipai.springboot.module.service.InventoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Author: 曹朋飞
 * @Date: 2018/08/22 17:53
 * 
 * 库存
 */
@Service
public class InventoryServiceImpl implements InventoryService{

    @Autowired
    InventoryDao inventoryDao;
    @Autowired
    ProductDao productDao;
    @Autowired
    GoodsDao goodsDao;

    //分页查询
    @Override
    public Response selectAllProductByPage(Integer page, Integer size, String draw, String productCategoryId, Integer isAudit,
                                           String search) {
        Integer start = (page-1) * size;
        List<Map<String, Object>> inventories = productDao.selectAllProductByPage(start, size, productCategoryId, isAudit, search);
        Integer totalNum = productDao.selectAllProductByPageAmount(productCategoryId, isAudit, search);
        PageResult<Map<String, Object>> pageList = new PageResult<>(inventories,page,size,totalNum, draw);
        Response response = new Response();
        response.setCode(RetCode.SUCCESS);
        response.put("pageList", pageList);
        return response;
    }
    
    

    //分页查询单一货品的所有商品
    @Override
    public Response selectAllGoodsByProductId(Integer page, Integer size, String draw, String spuNumber) {
        Integer start = (page-1) * size;
        List<Map<String, Object>> inventories = goodsDao.selectAllGoodsByProductId(start, size, spuNumber);
        Integer totalNum = goodsDao.selectAllGoodsByProductIdAmount(spuNumber);
        PageResult<Map<String, Object>> pageList = new PageResult<>(inventories,page,size,totalNum, draw);
        Response response = new Response();
        response.setCode(RetCode.SUCCESS);
        response.put("pageList", pageList);
        return response;
    }

}
